function SendDeploymentMail ([string]$OntimeReportLink, [string]$status)
{
  $_dir = Get-ScriptDir

	[xml]$Deploymentinfo = get-content ([system.IO.Path]::GetFullPath("$_dir\..\CommonProductParameters.xml"))
	
	$productname = $Deploymentinfo.variables.ProductName
	$version = $Deploymentinfo.variables.ProductVersion
	
	[xml]$config = Get-Content ([system.IO.Path]::GetFullPath("$_dir\..\Notifications.xml"))
  $NotificationManagement = $config.NotificationManagement
	
	#Process per Notification group
  if ($NotificationManagement -ne $null)
  {	
		foreach ($targetenvironment in $NotificationManagement.targetenvironments.targetenvironment)
		{
		  if ($targetenvironment.name -eq $TargetEnv)
			{	
			  $mailserver = $targetenvironment.emailNotifications.primarySmtpServer
			  $client = new-object System.Net.Mail.SmtpClient $mailserver
				
				#send an email to each group concerned with the target environment
				foreach ($groupValue in $targetenvironment.emailNotifications.NotificationGroup)
				{				
 					$emailArray = @() #clear arrays for new group
					$group = @()
					$group += $NotificationManagement.Users.user | where {$_.NotificationGroup -eq $groupValue}
					$group | %{$emailArray += $_.email} 
					$emailtemplate = $NotificationManagement.NotificationGroups.NotificationGroup | where {$_.name -eq $group[0].NotificationGroup} 
					$template = $NotificationManagement.emailTemplates.emailTemplate | where {$_.name -eq $emailTemplate.template}
					$msg = new-object System.Net.Mail.MailMessage
					$emailArray | %{$msg.To.Add($_)}
				
					$subject = "$Status deployment of $productname Version $version to $TargetEnv environment."
					$msg.subject = $subject
					$bodymsg = ""
					
					if (-not [system.String]::IsNullOrEmpty($OntimeReportLink))
					{
					  $bodymsg = "OnTime Report Link`r`n `r`n"
						$bodymsg = $bodymsg + "`"$OntimeReportLink`"`r`n`r`n"
					}
					$bodymsg = $bodymsg + "$Status deployment of $productname Version $version to $TargetEnv environment."
					
					$msg.Body = $bodymsg
					$msg.from = $template.from
					
				if ($template.attachLog -eq "TRUE")
      	{
						$logFiles = dir -Filter *.log
						foreach ($logFile in $logFiles)
						{
          	  $attachment = new-object System.Net.Mail.Attachment $logFile.fullname
          	  $msg.Attachments.Add($attachment)	
						}
      	}

      		$client.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials    
					$client.Send($msg)
				}		
			}
		}
  }
}
